/*
Given an integer array, sort the integer array such that the concatenated integer of the result array is max. e.g. [4, 94, 9, 14, 1] will be sorted to [9,94,4,14,1] where the result integer is 9944141
- Anonymous on February 18, 2011
*/

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>

using namespace std;


bool myComp(int a, int b)
{
    ostringstream os1, os2;
    os1 << a;
    os2 << b;
    return os1.str() + os2.str() < os2.str() + os2.str();
}

int main(int argc, char **argv)
{
    int a[] = {4,94, 9, 14, 1};
    vector<int> num(a, a + sizeof(a)/sizeof(int));
    sort(num.begin(), num.end(), myComp);
    for (int i = 0; i < num.size(); i++)
	cout << num[i] << " " ;    
}
